package cn.leedsoft.luma.plugins.quartz;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by leeds on 2016/6/20.
 */
public abstract class AbstractJobService implements Job, InitializingBean{
    //-----------------------------------------------------------
    //interfaces for a concrete job service
    //-----------------------------------------------------------
    @Autowired
    protected SchedulerAdapterService schedulerAdapterService;
    protected abstract void dealJob(JobExecutionContext context);
    public abstract void triggerJob(JobDataMap jobDataMap);
    public void triggerJob() {
        triggerJob(new JobDataMap());
    }
//    {//实例初始化块
//
//    }
    //---------------------
    //implements Job
    //---------------------
    public void execute(JobExecutionContext context) throws JobExecutionException {
        dealJob(context);
    }

    //--------------------------------------------------
    //implements InitializingBean
    //--------------------------------------------------
    public void afterPropertiesSet() throws Exception {
        schedulerAdapterService.setJobClass(this.getClass());
    }
}
